package com.jiaoyou.baojian.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.jiaoyou.baojian.R;
import com.jiaoyou.baojian.adapter.TopPagerAdapter;
import com.jiaoyou.baojian.wiget.UnScrollableViewPager;
import com.lhh.apst.library.AdvancedPagerSlidingTabStrip;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BangActivity extends BaseActivity {

    @BindView(R.id.tabs)
    AdvancedPagerSlidingTabStrip tabs;
    @BindView(R.id.viewpager)
    UnScrollableViewPager viewpager;
    @BindView(R.id.back)
    ImageView back;
    private TopPagerAdapter topPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

        viewpager.setPagingEnabled(true);
        topPagerAdapter = new TopPagerAdapter(getSupportFragmentManager());
        viewpager.setAdapter(topPagerAdapter);
        tabs.setViewPager(viewpager);
        tabs.getTabAt(0).setSelected(true);
        tabs.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                for(int i = 0; i < topPagerAdapter.getCount(); i++){
                    tabs.getTabAt(i).setSelected(false);
                }
                tabs.getTabAt(position).setSelected(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public int getContentView() {
        return R.layout.activity_bang;
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        onBackPressed();
    }
}
